package com.shujia.spark.mllib

import org.wltea.analyzer.core.IKSegmenter
import org.wltea.analyzer.core.Lexeme

import java.io.StringReader
import scala.collection.mutable.ListBuffer

object IKUtil {
  def main(args: Array[String]): Unit = {
    val list: List[String] = fit("自古刀扇过背刺")
    println(list)

  }

  def fit(text: String): List[String] = {
    println("fit")
    //ListBuffer: 可变集合
    val buffer = new ListBuffer[String]
    val sr = new StringReader(text)
    val ik = new IKSegmenter(sr, true)
    //获取第一个词语
    var lex: Lexeme = ik.next()
    while (lex != null) {
      //获取词语内容
      val word: String = lex.getLexemeText
      buffer += word
      //获取下一个词语
      lex = ik.next()
    }
    buffer.toList
  }
}
